package com.ruoyi.system.youshuda;

import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.StringUtils;
import com.zgl.youshuda.core.domain.dto.ModelTablePageDomain;
import com.zgl.youshuda.core.utils.CommonUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * 表格数据处理
 */
public class TableSupportInYsd
{
    /**
     * 当前记录起始索引
     */
    public static final String PAGE_NUM = "pageNum";

    /**
     * 每页显示记录数
     */
    public static final String PAGE_SIZE = "pageSize";

    /**
     * 排序列
     */
    public static final String ORDER_BY_COLUMN = "orderByColumn";

    /**
     * 排序的方向 "desc" 或者 "asc".
     */
    public static final String IS_ASC = "isAsc";

    /**
     * 分页参数合理化
     */
    public static final String REASONABLE = "reasonable";

    public static final String List = "List";
    public static final String Detail = "Detail";
    public static final String Add = "Add";
    public static final String Update = "Update";
    public static final String Delete = "Delete";

    public static final String Import = "Import";

    public static final String Export = "Export";
    public static final String ExportTemp = "ExportTemp";

    /**
     * 封装分页对象
     */
    public static ModelTablePageDomain getPageParams(Map<String,Object> params)
    {
        ModelTablePageDomain modelTablePageDomain=new ModelTablePageDomain();
        if(params==null){
            return modelTablePageDomain;
        }
        //页码
        modelTablePageDomain.setPageNum(Convert.toInt(params.get(PAGE_NUM), 1));
        params.remove(PAGE_NUM);
        //每页条数
        modelTablePageDomain.setPageSize(Convert.toInt(params.get(PAGE_SIZE), 10));
        params.remove(PAGE_SIZE);
        //排序
        modelTablePageDomain.setOrderByColumn(Convert.toStr(params.get(ORDER_BY_COLUMN), "create_time"));
        params.remove(ORDER_BY_COLUMN);
        //排序的方向 "desc" 或者 "asc".
        modelTablePageDomain.setIsAsc(Convert.toStr(params.get(IS_ASC), "desc"));
        params.remove(IS_ASC);
        //参数
        Map<String,Object> columnParams=new HashMap<>();
        for(Map.Entry<String,Object> column:params.entrySet()){
            //值为空的不传递
            if(column.getValue() == null || StringUtils.isEmptyIncludeNull(String.valueOf(column.getValue()))){
                continue;
            }
            columnParams.put(CommonUtil.humpToLine(column.getKey()),column.getValue());
        }
        modelTablePageDomain.setParams(columnParams);

        return modelTablePageDomain;
    }
}
